﻿using System;
using System.Web.UI;
using TalentRecruitmentSystem.Manage;

namespace TalentRecruitmentSystem.Pages
{
    public partial class Home : System.Web.UI.Page
    {
        UserInfoManage um = new UserInfoManage();
        CompanyInfoManage cm = new CompanyInfoManage();
        protected void Page_Load(object sender, EventArgs e)
        {
            #region
            //string str = Request.QueryString["Name"];
            //if (str == null)
            //{
            //    str = "";
            //    Session.Add("stringInSession", str);
            //}
            //if (!this.IsPostBack)
            //{
            //    if (str != null)
            //    {
            //        Txt_id.Visible = false;
            //        Txt_psw.Visible = false;
            //        Tbox_id.Visible = false;
            //        Tbos_psw.Visible = false;
            //        IBtn_Yes.Visible = false;
            //        img_log_in.Visible = false;
            //        RadioButton1.Visible = false;
            //        RadioButton2.Visible = false;
            //        lbl1.Text = "欢迎你：";
            //        lbl2.Text = str;
            //        LinkButton1.Text = "退出";
            //    }
            //}
            #endregion
            string str = Tbox_id.Text;
            Session.Add("tInSession", str);
            if (!this.IsPostBack)
            {
                //string str2 = "";
                //Session.Add("perInSession", str2);
                if (Session["perInSession"] != "" && Session["perInSession"] != null)
                {
                    Txt_id.Visible = false;
                    Txt_psw.Visible = false;
                    Tbox_id.Visible = false;
                    Tbos_psw.Visible = false;
                    IBtn_Yes.Visible = false;
                    img_log_in.Visible = false;
                    RadioButton1.Visible = false;
                    RadioButton2.Visible = false;
                    lbl1.Text = "欢迎你：";
                    lbl2.Text = Session["perInSession"].ToString();
                    LinkButton1.Text = "退出";
                }
                else
                { 
                
                
                }
            }
        }
        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {
            if (Tbox_id.Text != "" && Tbos_psw.Text != "")
            {
                string s = Tbox_id.Text;
                if (RadioButton1.Checked)
                {
                    if (Tbos_psw.Text == um.getUserInfoByUserName(s).Password)
                    {
                        Txt_id.Visible = false;
                        Txt_psw.Visible = false;
                        Tbox_id.Visible = false;
                        Tbos_psw.Visible = false;
                        IBtn_Yes.Visible = false;
                        img_log_in.Visible = false;
                        RadioButton1.Visible = false;
                        RadioButton2.Visible = false;
                        lbl1.Text = "欢迎你：";
                        lbl2.Text = um.getUserInfoByUserName(s).UserName;
                        Session.Add("perInSession", um.getUserInfoByUserName(s).UserName);
                        LinkButton1.Text = "退出";
                        Session["user"] = lbl2.Text;
                    }
                    else
                    {
                        Response.Write("<script>window.alert('用户名或密码错误！');</script>");
                    }
                }
                else
                {
                    if (Tbos_psw.Text == cm.getCompanyInfoByUserName(s).Password)
                    {
                        Txt_id.Visible = false;
                        Txt_psw.Visible = false;
                        Tbox_id.Visible = false;
                        Tbos_psw.Visible = false;
                        IBtn_Yes.Visible = false;
                        img_log_in.Visible = false;
                        RadioButton1.Visible = false;
                        RadioButton2.Visible = false;
                        lbl1.Text = "欢迎你：";
                        lbl2.Text = cm.getCompanyInfoByUserName(s).UserName;
                        Session.Add("comInSession", cm.getCompanyInfoByUserName(s).UserName);
                        LinkButton1.Text = "退出";
                        Session["user"] = lbl2.Text;
                    }
                    else
                    {
                        Response.Write("<script>window.alert('用户名或密码错误！');</script>");
                    }
                }
            }
            else
            {
                Response.Write("<script>window.alert('请输入用户名，密码！');</script>");
            }
        }

        protected void btnExit_Click(object sender, EventArgs e)
        {
            Txt_id.Visible = true;
            Txt_psw.Visible = true;
            Tbox_id.Visible = true;
            Tbox_id.Text = "";
            Tbos_psw.Visible = true;
            Tbos_psw.Text = "";
            IBtn_Yes.Visible = true;
            img_log_in.Visible = true;
            RadioButton2.Visible = true;
            RadioButton1.Visible = true;
            lbl1.Text = "";
            lbl2.Text = "";
            LinkButton1.Text = "";
        }

        protected void LinkButton1_Click(object sender, ImageClickEventArgs e)
        {
            this.MultiView1.ActiveViewIndex = 0;
            ad_title_img1.ImageUrl = "../Images/ad_title_img1_select.png";
            ad_title_img2.ImageUrl = "../Images/ad_title_img2.png";
            ad_title_img3.ImageUrl = "../Images/ad_title_img3.png";
            
        }
        protected void LinkButton2_Click(object sender, ImageClickEventArgs e)
        {
            this.MultiView1.ActiveViewIndex = 1;
            ad_title_img1.ImageUrl = "../Images/ad_title_img1.png";
            ad_title_img2.ImageUrl = "../Images/ad_title_img2_select.png";
            ad_title_img3.ImageUrl = "../Images/ad_title_img3.png";
        }
        protected void LinkButton3_Click(object sender, ImageClickEventArgs e)
        {
            this.MultiView1.ActiveViewIndex = 2;
            ad_title_img1.ImageUrl = "../Images/ad_title_img1.png";
            ad_title_img2.ImageUrl = "../Images/ad_title_img2.png";
            ad_title_img3.ImageUrl = "../Images/ad_title_img3_select.png";
        }

        protected void img_write_Click(object sender, ImageClickEventArgs e)
        {
            if((string)Session["user"]==""||Session["user"]==null)
            {
                Response.Redirect("landing.aspx");
            }else
            {
                Response.Redirect("WriteResume.aspx");
            }
        }
    
    }
}